// hyb_yl/czhuanjiasubpages/pages/healreport/index.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    focus: true,
    progress: 10, //进度条
    date: [],
    currindex: 0, //第几题
    textvalue: '',
    tranbiglist: [], //体检报告数组
    
    data_arr: [],
    chosesmoke: false,
    chosewine: false,
    choseactive: false,
    list:{
      question:"体检图片",
      img: [],
    },
    
    blockques1: '', //担心体检结果
    blockques2: '', //不舒服表现
    picker_key1: true,
    picker_key2: true,
    picker_key3: true
  },
 
 
  // 上传图片
  uploadimg2: function() {
    let that = this;
    var uniacid = app.siteInfo.uniacid;
    var data_arr = that.data.data_arr
    wx.chooseImage({
      count: 5,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        for (var i = 0; i < tempFilePaths.length; i++) {
          wx.uploadFile({
            url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadback&m=hyb_yl',
            filePath: tempFilePaths[i],
            name: 'upfile',
            formData: {},
            success: function(res) {
              console.log(res)
              that.data.list.img=data_arr.push(res.data)
              that.setData({
                img2: data_arr
              })
            }
          })
        }
      }
    })
  },
  // 删除图片
  downimg2: function(e) {
    console.log(e.currentTarget.dataset.index)
    let index = e.currentTarget.dataset.index;
    this.data.img2.splice(index, 1);
    this.setData({
      img2: this.data.img2
    })
  },
  next:function(){
    var that = this
    var img2 = that.data.img2
    wx.setStorageSync('img2', that.data.img2) 
    if(img2.length<=0){
      wx.showToast({
        title: '请先上传体检报告',
        icon:'none'
      })
    }else{
      var zid = that.data.zid
      var name = that.data.name
      var keywords = that.data.keywords
      var j_id = that.data.j_id
      var list = {question:"体检图片",img:img2};
      var tranbiglist = that.data.tranbiglist
      tranbiglist.push(list)
     that.setData({
       tranbiglist:tranbiglist
     })
      app.util.request({
        'url': 'entry/wxapp/Hzbingli.addbingli',
        data: {
          msglist: tranbiglist,
          sicktel: that.data.tel,
          openid: wx.getStorageSync('openid'),
          j_id: j_id,
          keywords: keywords
        },
        success: function(res) {
          console.log(res)
          var bl_id = res.data
          //插入问诊订单
          var name = that.data.name
          app.util.request({
            'url': 'entry/wxapp/Hzbingli.addorder',
            data: {
              zid: zid,
              name: name,
              keywords: keywords,
              openid: wx.getStorageSync('openid'),
              bl_id: bl_id,
              money: that.data.newmoney,
              j_id: j_id,
            },
            success: function(res) {
              console.log(res)
              var name = res.data.name
              var order = res.data.order
              var money = that.data.newmoney
              var oid = res.data.oid
              wx.navigateTo({
                url: '/hyb_yl/czhuanjiasubpages/pages/questends/index?phone=' + that.data.tel + '&zid=' + zid + '&name=' + name + '&keywords=' + keywords + '&j_id=' + j_id + '&allone_key=1' + '&name=' + name + '&order=' + order + '&money=' + money + '&oid=' + oid + '&bl_id=' + bl_id
              })
            }
          })
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var that = this
    var zid = options.zid
    var name = options.name
    var keywords = options.keywords
    console.log(keywords)
    var j_id = options.j_id
    var tel = options.tel
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.docinfo',
      data: {
        zid: zid,
        key: keywords,
      },
      success: function(res) {
        that.setData({
          newmoney: res.data.data.newmoney
        })
      }
    })
    app.util.request({
      'url': 'entry/wxapp/Hzbingli.url',
      success: function(res) {
        console.log(res)
        that.setData({
          url: res.data,
          trandatas: options,
          zid: zid,
          name: name,
          keywords: keywords,
          j_id: j_id,
          tel: tel
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

})